package dao

import "aglaia/internal/model"

func (d *Dao) FirstOrCreateTag(name string) (model.Tag, error) {
	tag := model.Tag{
		Name: name,
	}

	if err := tag.FirstOrCreate(d.engine); err != nil {
		return model.Tag{}, err
	}

	return tag, nil
}

func (d *Dao) DeleteTag(id uint) error {
	tag := model.Tag{Model: model.Model{Id: id}}
	return tag.Delete(d.engine)
}

func (d *Dao) Tags() ([]model.Tag, error) {
	var tag model.Tag
	return tag.List(d.engine)
}
